﻿using System;
using System.ComponentModel.Composition;
using Cubicle.Core.Interfaces;
using Cubicle.Core.Shared;

namespace Cubicle.Core.Processors.Invoke
{
    //[Export("Cubicle.Processors.Invoke.InstructionFilter", typeof(IProcessor<InstructionRequest>))]
    //[ExportMetadata("Name", "InstructionFilter")]
    //[ExportMetadata("Description", "Filters instructions to restrict allowed RequestTypes")]
    //public class InstructionFilter : InstructionRequestProcessor
    //{
    //    // Nlog
    //    private static NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();

    //    public RequestType Filter { get; set; }

    //    public InstructionFilter() : base(RequestType.All)
    //    {
    //        var allowed = Helpers.GetKey("allowed");
    //        try
    //        {
    //            Filter = (RequestType)Enum.Parse(typeof(RequestType), allowed);
    //        } catch (Exception e)
    //        {
    //            _logger.ErrorException(e, "Could not parse filter setting. Using AllIncoming.");
    //            Filter = RequestType.AllIncoming;
    //        }
    //    }

    //    #region Overrides of ConditionalProcessor<InstructionRequest>

    //    public override InstructionRequest ConditionalProcess(InstructionRequest request)
    //    {
    //        if ((request.Type() & Filter) == request.Type())
    //            return request;
    //        request.Fail("Filtered.");
    //        return request;
    //    }

    //    #endregion
    //}
}
